package org.zt.ccty.springboot_mybatis_demo.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.zt.ccty.springboot_mybatis_demo.model.User;
import org.zt.ccty.springboot_mybatis_demo.service.UserService;
import org.zt.ccty.springboot_mybatis_demo.service.UserServiceImpl;
import org.zt.ccty.springboot_mybatis_demo.zk.ZkConfig;

import com.alibaba.fastjson.JSON;



@Controller
@RequestMapping("/users")
public class UsersController {



    private Logger logger = Logger.getLogger(UsersController.class);

    @Autowired
    private UserService userService;
    @Autowired
    private ZkConfig zkConfig;
	@Value("${mongodb.host}")
	private String HOST;
    @RequestMapping("/getUserInfo")
    @ResponseBody
    public Object getUserInfo() {
    	
    	List<User> users = userService.getUserInfo();
        if(users!=null){
            System.out.println(JSON.toJSON(users));
            logger.info("user.getAge():"+JSON.toJSON(users));
        }
        zkConfig.getZKAddress("230");
        return zkConfig.getZKAddress("230");
    }
    @RequestMapping("/getUserInfoById")
    @ResponseBody
    public User getUserInfoById(HttpServletRequest request,String id) {
    	User user = userService.getUserInfoById(id);
        if(user != null){
            System.out.println(JSON.toJSON(user));
            logger.info("user.getAge():"+user.getAge());
        }
        return user;
    }
    @RequestMapping("/getCityName")
    @ResponseBody
    public String getcityName(){
    	String cityName = HOST;
    	cityName = userService.testMongoDB();
    	return cityName;
    }
}
